<template>
	<view class="classify">
		<view class="navBar">
			<view class="right" @click="toSearch">
				<input type="text" value="" placeholder="输入关键字"/>
				<icon type="search" size="34rpx" color="#1296db"></icon>
			</view>
		</view>
		<view class="list" ref="list" :style="{height:listHight+'rpx'}">
			<scroll-view scroll-y="true" class="categoryList">
				<view class="categoryItem" :class="chooseCategory==item?'chooseStyle':''" v-for="(item,index) in category" :key="index" @click="toCategory(item)">
					{{item}}
				</view>
			</scroll-view>
			<scroll-view scroll-y="true" class="goodsList">
				<view class="goodsItem" v-for="(item,index) in goods" :key="index" @click="toDetail(item.goodsId)">
					<image class="image" :src="item.image" mode="widthFix"></image>
					<view class="goodsName">{{item.goodsName}}</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				category:[],
				goods: [],
				chooseCategory:'',
				listHight:0,
			}
		},
		onLoad() {
			this.getCategory();
			
		},
		methods: {
			//获取货物种类
			getCategory(){
				uni.request({
					url: 'http://localhost:8080/goods/findCategoryList',
					method: 'GET',
					data: {},
					success: res => {
						this.category=res.data.category;
						this.getGoods(this.category[0]);
						this.getListHeight();
					},
					fail: () => {},
					complete: () => {}
				});
			},
			//获取货物
			getGoods(category) {
				this.chooseCategory=category;
				uni.request({
					url: 'http://localhost:8080/goods/findByCategory',
					method: 'GET',
					data: {
						category:category,
					},
					success: res => {
						this.goods = res.data;
					},
					fail: () => {},
					complete: () => {}
				});
			},
			//前往详情页
			toDetail(id) {
				uni.navigateTo({
					url: '/pages/detail/detail?id=' + id,
				});
			},
			//前往类别
			toCategory(item){
				this.getGoods(item);
			},
			toSearch(){
				uni.navigateTo({
					url: '/pages/search/search',
				});
			},
			//获取窗口界面高度
			// getListHeight(){
			// 	const list=this.$refs.list.$el;
				
			// 	uni.getSystemInfo({
			// 	  success: function(res) {
			// 		list.style.height=res.windowHeight-res.windowBottom-2+"px";
			// 		this.listHight= (res.windowHeight*2)*2;
			// 		console.log(this.listHight);
			// 	  }
			// 	});
			// }
			getListHeight(){
				let wHeight=uni.getSystemInfoSync().windowHeight;
				let wBottom=uni.getSystemInfoSync().windowBottom;
				console.log(uni.getSystemInfoSync().screenHeight);
				console.log(wHeight,wBottom);
				this.listHight=(wHeight-wBottom)*2;
				// #ifdef MP-WEIXIN
				this.listHight=(wHeight-75)*2;
				// #endif
				console.log(this.listHight);
			}
			
		}
	}
</script>

<style lang="scss">
	.navBar {
		display: flex;
		height: 100rpx;
		background-color: white;
		align-items: center;
		padding: 0 30rpx;
		/* #ifdef MP-WEIXIN */
		padding-top: 100rpx;
		/* #endif */
		.right {
			flex: 1;
			position: relative;
			width: 200rpx;
		}
		input {
			padding: 10rpx 0rpx;
			padding-left: 60rpx;
			border: 1rpx solid #ccc;
			border-radius: 50rpx;
			font-size: 30rpx;
		}
	
		icon {
			position: absolute;
			left: 20rpx;
			top: 16rpx;
		}
	}
	.list{
		display: flex;
		.categoryList{
			flex:1;
		
			.chooseStyle{
				color: #1296db;
				border-left: 6rpx solid #1296db;
			}
			.categoryItem{
				padding: 30rpx 0 30rpx 30rpx;
			}
			
		}
		
		.goodsList{
			flex: 3;
			.goodsItem{
				display: inline-block;
				margin: 15rpx;
				width: 250rpx;
				height: 380rpx;
				background-color: white;
				border-radius: 20rpx;
				text-align: center;
				overflow: hidden;
			}
			.image{
				width: 100%;
			}
			.goodsName{
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
				overflow: hidden;
			}
		}
	}
	
	
	
</style>
